package com.niit.order.web;


import com.niit.order.pojo.Order;
import com.niit.order.service.IOrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yaojianfeng
 */
@RestController
@RequestMapping("order")
public class OrderController {

   @Resource
   private IOrderService orderService;
   @Resource
   private IOrderService orderServiceCenter;
   @Resource
   private IOrderService orderServiceFeign;


    /**
     * 最原始的固定IP查询
     * @param orderId
     * @return
     */
    @GetMapping("{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) {

        return orderService.queryOrderById(orderId);
    }

    /**
     * 通过RestTemplate进行负载均衡
     * @param orderId
     * @return
     */
    @GetMapping("/center/{orderId}")
    public Order queryOrderByUserIdFromCenter(@PathVariable("orderId") Long orderId) {

        return orderServiceCenter.queryOrderById(orderId);
    }

    /**
     * 通过Feign调用,更加优雅
     * @param orderId
     * @return
     */
    @GetMapping("/feign/{orderId}")
    public Order queryOrderByUserIdFromFeign(@PathVariable("orderId") Long orderId) {

        return orderServiceFeign.queryOrderById(orderId);
    }
}
